import math

"""向量"""
class Vector:

    def __init__(self,lst):
        self._values = list(lst)

    @classmethod
    def zero(cls, dim ):
        """返回一个dim维度的零向量"""
        return cls([0]*dim)

    def norm(self):
        """返回向量的摸"""
        return math.sqrt(sum(e**2 for e in self))

    def normalize(self):
        """返回向量的单位向量"""
        return 1 / self.norm() * Vector(self._values)

    def __add__(self, other):
        """向量加法，返回结果向量"""
        assert len(self) == len(other), \
                                "向量长度不相等."
        return Vector( [a + b for a,b in zip(self,other)])

    def __sub__(self, other):
        """向量减法，返回结果向量"""
        assert len(self) == len(other), \
                                "向量长度不相等."
        return Vector([a - b for a, b in zip(self, other)])

    def dot(self,other):
        """向量点成，返回标量(数值)"""
        assert len(self) == len(other), \
                                "向量长度不相等."
        return sum([a * b for a, b in zip(self, other)])


    def __mul__(self, k):
        """返回数量乘法(向量乘以一个数):self*K"""
        return Vector([k*e for e in self])

    def __rmul__(self, k):
        """返回数量乘法(向量乘以一个数):k*self"""
        return self*k

    def __pos__(self):
        """向量取正的结果向量"""
        return 1*self

    def __neg__(self):
        """向量取负的结果向量"""
        return -1*self

    def __iter__(self):
        """返回向量的迭代器"""
        return self._values.__iter__()

    def __len__(self):
        """返回向量长度（有多少元素/向量的维度）"""
        return len(self._values)

    def __getitem__(self, index):
        """取向量的第index个元素"""
        return self._values[index]

    def __repr__(self):
        return "Vector({})".format(self._values)

    def __str__(self):
        return "({})".format(", ".join( str(e) for e in self._values ))